﻿

CREATE PROCEDURE [dbo].[proc_Employee_PostWage_GetItem]
	(
		@PostId int,
		@GradeId int,
		@Eid int
	)
AS
	--入职日期|公司Id
--	Declare @RuZhiDate DateTime,@CompanyId int
--	Select @RuZhiDate=RuZhiDate,@CompanyId=CompanyId From employee Where Id=@Eid
	Declare @RuZhiDate DateTime,@CompanyId int,@Pid int,@Cid int,@UserName nvarchar(50)
	Select @RuZhiDate=RuZhiDate,@CompanyId=CompanyId,@Pid=Pid,@Cid=Cid,@UserName=UserName From employee Where Id=@Eid
	--选择职级的时候
	begin
--		Select 
--		 isnull((select Wage from Grade where id=@GradeId),0) as BasicWage
--		,isnull(PostWage,0) as PostWage
--		,isnull((datediff(dd,@RuZhiDate,getdate())/360*100),0) as WorkWage
--		,isnull(JxWage,0) as JxWage
--		,isnull(ManQin,0) as ManQin
--		,isnull((select sum(Amount) from Employee_Allowance EA where postid=@PostId And EAId in (Select EAC.EAId From Employee_Allowance_Company EAC Where EAC.CompanyId=@CompanyId)),0) as Allowance
--		
--		From Post
--		Where Id=@PostId
		Select 
		 isnull((select Wage from Grade where id=@GradeId),0) as BasicWage
		,isnull(PostWage,0) as PostWage
		,isnull((datediff(mm,@RuZhiDate,getdate())/12*100),0) as WorkWage
		,isnull(JxWage,0) as JxWage
		,isnull(ManQin,0) as ManQin
		,isnull((select sum(EA.Amount) from Employee_Allowance EA where EA.postid=@PostId And EA.Pid=@Pid And EA.Cid=@Cid),0) as Allowance
		,IsNull((Select Sum(FA.Amount) From Employee_FixedAllowance FA Where FA.UserName = @UserName),0) as FixedAllowance
		From Post
		Where Id=@PostId
	end
	
	RETURN

